<?php
namespace yan\currency\factory;
class EcbEuropa extends \yan\currency\AbstractFactory{
	public function run($service){
		$url = 'https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
		$response = $service->curl->build($url)->run();
		$dom = new \DOMDocument('1.0', 'UTF-8');
		$dom->loadXml($response);

		$cube = $dom->getElementsByTagName('Cube')->item(0);

		$currencies = [];

		$currencies['EUR'] = '1.0000';

		foreach ($cube->getElementsByTagName('Cube') as $currency) {
			if ($currency->getAttribute('currency')) {
				$currencies[$currency->getAttribute('currency')] = $currency->getAttribute('rate');
			}
		}
		return $currencies;
	}
}